<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
      <div ref="echart" id="main" style="width: 750px;height:400px;"></div>
    </el-card>
  </div>
</template>
<script>
import * as echarts from 'echarts'
import { getEchartsDataApi } from '@/api/report'
import _ from 'lodash'
// 符合项目的基本结构，不包含数据
const options = {
  title: {
    text: '用户来源'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      label: {
        backgroundColor: '#E9EEF3'
      }
    }
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: [
    {
      boundaryGap: false
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ]
}
export default {
  name: 'ReportIndex',
  data() {
    return {
      options
    }
  },
  mounted() {
    this.getEcharts()
  },
  methods: {
    async getEcharts() {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(this.$refs.echart)
      const optionsApi = await getEchartsDataApi()
      // 接口返回的数据只是部分options选项，需要和当前的配置进行合并
      _.merge(this.options, optionsApi)
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(this.options)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
